<div class="content-section introduction">
    <div class="feature-intro">
        <h1>SelectButton</h1>
        <p>SelectButton is a form component to choose a value from a list of options using button elements.</p>
    </div>
    <app-demoActions github="selectbutton" stackblitz="selectbutton-demo"></app-demoActions>
</div>

<div class="content-section implementation">
    <div class="card">
        <h5>Single Selection</h5>
        <p-selectButton [options]="stateOptions" [(ngModel)]="value1" optionLabel="label" optionValue="value"></p-selectButton>

        <h5>Multiple Selection</h5>
        <p-selectButton [options]="paymentOptions" [(ngModel)]="value2" multiple="multiple" optionLabel="name" optionValue="value"></p-selectButton>

        <h5>Custom Template</h5>
        <p-selectButton [options]="justifyOptions" [(ngModel)]="value3" optionLabel="icon">
            <ng-template let-item>
                <i [class]="item.icon"></i>
            </ng-template>
        </p-selectButton>
    </div>
</div>

<div class="content-section documentation">
    <p-tabView>
        <p-tabPanel header="Documentation">
            <h5>Import</h5>
<app-code lang="typescript" ngNonBindable ngPreserveWhitespaces>
import &#123;SelectButtonModule&#125; from 'primeng/selectbutton';
</app-code>

            <h5>Getting Started</h5>
            <p>SelectButton requires a value to bind and a collection of options.</p>

<app-code lang="markup" ngNonBindable ngPreserveWhitespaces>
&lt;p-selectButton [options]="cities" [(ngModel)]="selectedCity" optionLabel="name"&gt;&lt;/p-selectButton&gt;
</app-code>
    
<app-code lang="typescript" ngNonBindable ngPreserveWhitespaces>
interface City &#123;
    name: string,
    code: string
&#125;

export class SelectButtonDemo &#123;

    cities: City[];

    selectedCity: City;

    constructor() &#123;
        this.cities = [
            &#123;name: 'New York', code: 'NY'&#125;,
            &#123;name: 'Rome', code: 'RM'&#125;,
            &#123;name: 'London', code: 'LDN'&#125;,
            &#123;name: 'Istanbul', code: 'IST'&#125;,
            &#123;name: 'Paris', code: 'PRS'&#125;
        ];
    &#125;

&#125;
</app-code>

            <h5>Value Binding</h5>
            <p>The option itself is bound to the model by default, use <i>optionValue</i> to customize the property to pass as the value.</p>
<app-code lang="markup" ngNonBindable ngPreserveWhitespaces>
&lt;p-selectButton [options]="cities" [(ngModel)]="selectedCityCode" optionLabel="name" optionValue="code"&gt;&lt;/p-selectButton&gt;
</app-code>
    
<app-code lang="typescript" ngNonBindable ngPreserveWhitespaces>
export class SelectButtonDemo &#123;

    cities: City[];

    selectedCityCode: string;

    constructor() &#123;
        this.cities = [
            &#123;name: 'New York', code: 'NY'&#125;,
            &#123;name: 'Rome', code: 'RM'&#125;,
            &#123;name: 'London', code: 'LDN'&#125;,
            &#123;name: 'Istanbul', code: 'IST'&#125;,
            &#123;name: 'Paris', code: 'PRS'&#125;
        ];
    &#125;

&#125;
</app-code>

            <h5>Selection</h5>
            <p>SelectButtons allows selection of either single or multiple items, this behavior is defined with the <i>multiple</i> property. In single case, model should be a single object reference whereas in multiple case should be an array.</p>

<app-code lang="markup" ngNonBindable ngPreserveWhitespaces>
&lt;p-selectButton [options]="cities" [(ngModel)]="selectedCities" optionLabel="name" [multiple]="true"&gt;&lt;/p-selectButton&gt;
</app-code>
    
<app-code lang="typescript" ngNonBindable ngPreserveWhitespaces>
export class SelectButtonDemo &#123;

    cities: City[];

    selectedCities: City[];

    constructor() &#123;
        this.cities = [
            &#123;name: 'New York', code: 'NY'&#125;,
            &#123;name: 'Rome', code: 'RM'&#125;,
            &#123;name: 'London', code: 'LDN'&#125;,
            &#123;name: 'Istanbul', code: 'IST'&#125;,
            &#123;name: 'Paris', code: 'PRS'&#125;
        ];
    &#125;

&#125;
</app-code>

            <h5>Disabled Options</h5>
            <p>Particular options can be prevented from selection using the <i>optionDisabled</i> property.</p>
<app-code lang="markup" ngNonBindable ngPreserveWhitespaces>
&lt;p-selectButton [options]="cities" [(ngModel)]="selectedCity" optionLabel="name" optionDisabled="inactive"&gt;&lt;/p-selectButton&gt;
</app-code>

<app-code lang="typescript" ngNonBindable ngPreserveWhitespaces>
export class SelectButtonDemo &#123;

    cities: City[];

    selectedCity: City;

    constructor() &#123;
        this.cities = [
            &#123;name: 'New York', code: 'NY', inactive: false&#125;,
            &#123;name: 'Rome', code: 'RM', inactive: true&#125;,
            &#123;name: 'London', code: 'LDN', inactive: false&#125;,
            &#123;name: 'Istanbul', code: 'IST', inactive: true&#125;,
            &#123;name: 'Paris', code: 'PRS', inactive: false&#125;
        ];
    &#125;

&#125;
</app-code>

            <h5>Model Driven Forms</h5>
            <p>SelectButton can be used in a model driven form as well.</p>
<app-code lang="markup" ngNonBindable ngPreserveWhitespaces>
&lt;p-selectButton [options]="cities" formControlName="selectedCity"&gt;&lt;/p-selectButton&gt;
</app-code>

            <h5>Custom Content</h5>
            <p>For custom content support define a ng-template where the local ng-template variable refers to an option in the options collection.</p>

<app-code lang="markup" ngNonBindable ngPreserveWhitespaces>
&lt;p-selectButton [options]="justifyOptions" [(ngModel)]="value" optionLabel="icon"&gt;
    &lt;ng-template let-item&gt;
        &lt;i [class]="item.icon"&gt;&lt;/i&gt;
    &lt;/ng-template&gt;
&lt;/p-selectButton&gt;
</app-code>

<app-code lang="typescript" ngNonBindable ngPreserveWhitespaces>
export class SelectButtonDemo &#123;

    justifyOptions: any[];

    value: any;

    constructor() &#123;    
        this.justifyOptions = [
            &#123;icon: 'pi pi-align-left', justify: 'Left'&#125;,
            &#123;icon: 'pi pi-align-right', justify: 'Right'&#125;,
            &#123;icon: 'pi pi-align-center', justify: 'Center'&#125;,
            &#123;icon: 'pi pi-align-justify', justify: 'Justify'&#125;
        ];
    &#125;
&#125;
</app-code>

            <h5>Properties</h5>
            <div class="doc-tablewrapper">
                <table class="doc-table">
                    <thead>
                    <tr>
                        <th>Name</th>
                        <th>Type</th>
                        <th>Default</th>
                        <th>Description</th>
                    </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td>options</td>
                            <td>array</td>
                            <td>null</td>
                            <td>An array of selectitems to display as the available options.</td>
                        </tr>
                        <tr>
                            <td>optionLabel</td>
                            <td>string</td>
                            <td>label</td>
                            <td>Name of the label field of an option.</td>
                        </tr>
                        <tr>
                            <td>optionValue</td>
                            <td>string</td>
                            <td>value</td>
                            <td>Name of the value field of an option.</td>
                        </tr>
                        <tr>
                            <td>optionDisabled</td>
                            <td>string</td>
                            <td>disabled</td>
                            <td>Name of the disabled field of an option.</td>
                        </tr>
                        <tr>
                            <td>multiple</td>
                            <td>boolean</td>
                            <td>false</td>
                            <td>When specified, allows selecting multiple values.</td>
                        </tr>
                        <tr>
                            <td>tabindex</td>
                            <td>number</td>
                            <td>0</td>
                            <td>Index of the element in tabbing order.</td>
                        </tr>
                        <tr>
                            <td>style</td>
                            <td>string</td>
                            <td>null</td>
                            <td>Inline style of the component.</td>
                        </tr>
                        <tr>
                            <td>styleClass</td>
                            <td>string</td>
                            <td>null</td>
                            <td>Style class of the component.</td>
                        </tr>
                        <tr>
                            <td>ariaLabelledBy</td>
                            <td>string</td>
                            <td>null</td>
                            <td>Establishes relationships between the component and label(s) where its value should be one or more element IDs.</td>
                        </tr>
                        <tr>
                            <td>disabled</td>
                            <td>boolean</td>
                            <td>false</td>
                            <td>When present, it specifies that the element should be disabled.</td>
                        </tr>
                        <tr>
                            <td>dataKey</td>
                            <td>string</td>
                            <td>null</td>
                            <td>A property to uniquely identify a value in options.</td>
                        </tr>
                    </tbody>
                </table>
            </div>

            <h5>Events</h5>
            <div class="doc-tablewrapper">
                <table class="doc-table">
                    <thead>
                    <tr>
                        <th>Name</th>
                        <th>Parameters</th>
                        <th>Description</th>
                    </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td>onChange</td>
                            <td>event.originalEvent: browser event<br />
                                event.value: single value or an array of values that are selected
                            </td>
                            <td>Callback to invoke when value changes.</td>
                        </tr>
                        <tr>
                            <td>onOptionClick</td>
                            <td>event.originalEvent: browser event<br />
                                event.option: SelectItem instance of the clicked button<br />
                                event.index: Index of the clicked button
                            </td>
                            <td>Callback to invoke when a button is clicked.</td>
                        </tr>
                    </tbody>
                </table>
            </div>

            <h5>Dependencies</h5>
            <p>None.</p>
        </p-tabPanel>

        <p-tabPanel header="Source">
            <a href="https://github.com/primefaces/primeng/tree/master/src/app/showcase/components/selectbutton" class="btn-viewsource" target="_blank">
                <span>View on GitHub</span>
            </a>
            <a href="https://stackblitz.com/edit/primeng-selectbutton-demo" class="btn-viewsource" style="margin-left: .5em;" target="_blank">
                <span>Edit in StackBlitz</span>
            </a>
<app-code lang="markup" ngNonBindable ngPreserveWhitespaces>
&lt;h5&gt;Single Selection&lt;/h5&gt;
&lt;p-selectButton [options]="stateOptions" [(ngModel)]="value1" optionLabel="label" optionValue="value"&gt;&lt;/p-selectButton&gt;

&lt;h5&gt;Multiple Selection&lt;/h5&gt;
&lt;p-selectButton [options]="paymentOptions" [(ngModel)]="value2" multiple="multiple" optionLabel="name" optionValue="value"&gt;&lt;/p-selectButton&gt;

&lt;h5&gt;Custom Template&lt;/h5&gt;
&lt;p-selectButton [options]="justifyOptions" [(ngModel)]="value3" optionLabel="icon"&gt;
    &lt;ng-template let-item&gt;
        &lt;i [class]="item.icon"&gt;&lt;/i&gt;
    &lt;/ng-template&gt;
&lt;/p-selectButton&gt;
</app-code>

<app-code lang="typescript" ngNonBindable ngPreserveWhitespaces>
import &#123;Component&#125; from '@angular/core';

@Component(&#123;
    templateUrl: './selectbuttondemo.html'
&#125;)
export class SelectButtonDemo &#123;

    stateOptions: any[];

    paymentOptions: any[];

    justifyOptions: any[];

    value1: string = "off";

    value2: number;

    value3: any;

    constructor() &#123;
        this.stateOptions = [&#123;label: 'Off', value: 'off'&#125;, &#123;label: 'On', value: 'on'&#125;];

        this.paymentOptions = [
            &#123;name: 'Option 1', value: 1&#125;,
            &#123;name: 'Option 2', value: 2&#125;,
            &#123;name: 'Option 3', value: 3&#125;
        ];

        this.justifyOptions = [
            &#123;icon: 'pi pi-align-left', justify: 'Left'&#125;,
            &#123;icon: 'pi pi-align-right', justify: 'Right'&#125;,
            &#123;icon: 'pi pi-align-center', justify: 'Center'&#125;,
            &#123;icon: 'pi pi-align-justify', justify: 'Justify'&#125;
        ];
    &#125;
&#125;
</app-code>
        </p-tabPanel>
        <p-tabPanel header="StackBlitz">
            <ng-template pTemplate="content">
                <iframe src="https://stackblitz.com/edit/primeng-selectbutton-demo?embed=1" style="width: 100%; height: 768px; border: none;"></iframe>
            </ng-template>
        </p-tabPanel>
    </p-tabView>
</div>
